package com.aaa.service.impl;

import com.aaa.entity.SubscriptionFans;
import com.aaa.mapper.SubscriptionFansMapper;
import com.aaa.service.ISubscriptionFansService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Bean
 * @since 2021-09-05
 */
@Slf4j
@Service
public class SubscriptionFansServiceImpl extends ServiceImpl<SubscriptionFansMapper, SubscriptionFans> implements ISubscriptionFansService {

    @Autowired
    SubscriptionFansMapper subscriptionFansMapper;
    @Autowired
    NettyPushServerImpl nettyPushServer;


    public boolean add(Integer uid,String uname, Integer id){
        if (subscriptionFansMapper.add(uid, id)==1){
            nettyPushServer.pushidServer(id.toString(),uname+"关注了小主哦");
            return true;
        }else{
            return false;
        }
    }

    public List<Map<String,Object>> seleatten(Integer uid){
        List<Map<String, Object>> seleatter = subscriptionFansMapper.seleatter(uid);
        for (Map map:seleatter){
            Integer state = (Integer) map.get("state");
            if(state==0){
                Integer id = (Integer) map.get("id");
                SubscriptionFans subscriptionFans = new SubscriptionFans();
                subscriptionFans.setId(id);
                subscriptionFans.setState(1);
                subscriptionFansMapper.updateById(subscriptionFans);
            }
        }
        return seleatter;
    }
}
